package com.binguo.api.response.api;

import com.fasterxml.jackson.annotation.JsonInclude;

public class BaseChargeResp<T> {

    private int code;

    private String message;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public BaseChargeResp setCode(com.binguo.common.exception.ErrorCode errorCode) {
        this.code = errorCode.code;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public BaseChargeResp setMessage(String message) {
        this.message = message;
        return this;
    }

    public T getData() {
        return data;
    }

    public BaseChargeResp setData(T data) {
        this.data = data;
        return this;
    }

    private static final String DEFAULT_SUCCESS_MESSAGE = "SUCCESS";

    public static BaseChargeResp genSuccessResult() {
        return new BaseChargeResp()
                .setCode(com.binguo.common.exception.ErrorCode.SUCCESS)
                .setMessage(DEFAULT_SUCCESS_MESSAGE);
    }

    public static <T> BaseChargeResp<T> genSuccessResult(T data) {
        return new BaseChargeResp()
                .setCode(com.binguo.common.exception.ErrorCode.SUCCESS)
                .setMessage(DEFAULT_SUCCESS_MESSAGE)
                .setData(data);
    }

    public static BaseChargeResp genFailResult(String message) {
        return new BaseChargeResp()
                .setCode(com.binguo.common.exception.ErrorCode.FAIL)
                .setMessage(message);
    }
}
